/*
 * HackSQL
 * Copyright (C) 2008-2009
 *
 * Authors: Felipe Nascimento Silva Pena
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef HS_TYPES_H
#define HS_TYPES_H

#include <time.h>

#ifdef __GNUC__
# define HS_GCC_VERSION (__GNUC__ * 1000 + __GNUC_MINOR__)
#else
# define HS_GCC_VERSION 0
#endif

typedef unsigned int hs_uint;
typedef unsigned short int hs_short;
typedef char* hs_string;
typedef unsigned char hs_bool;

#undef SUCCESS
#undef FAILURE
#define SUCCESS 0
#define FAILURE 1

typedef enum {
	HS_PRIV_ALL    = 1<<0,
	HS_PRIV_SELECT = 1<<1,
	HS_PRIV_UPDATE = 1<<2,
	HS_PRIV_CREATE = 1<<3
} hs_privilege;

typedef struct {
	hs_uint name_len;
	hs_string name;	
	hs_uint privileges;
} hs_user;

typedef struct {
	hs_uint name_len;
	hs_string name;	
	hs_user **users;
	hs_uint num;
} hs_role;

typedef enum {
	HS_FIELD_INTEGER,
	HS_FIELD_VARCHAR,
	HS_FIELD_BOOL,
	HS_FIELD_CHAR,
	HS_FIELD_BLOB	
} hs_field_type;

typedef struct {
	hs_uint name_len;
	hs_string name;	
	hs_field_type type;
} hs_field;

typedef enum {
	HS_COLUMN_PK,
	HS_COLUMN_FK,
	HS_COLUMN_UNIQUE	
} hs_contraint_type;

typedef struct {
	hs_uint name_len;
	hs_string name;	
	hs_field **fields;
	hs_uint type;
	hs_uint num_fields;
} hs_contraint;

typedef struct {
	hs_uint name_len;
	hs_string name;
	hs_uint comment_len;
	hs_string comment;
	hs_field **fields;
	hs_uint num_fields;
	hs_contraint **constraints;
	hs_uint num_constraints;
	hs_uint num_rows;
	hs_uint version;
	time_t create_time;
	time_t update_time;
} hs_table;

typedef struct {
	hs_uint name_len;
	hs_string name;
	hs_uint num_tables;
	hs_table **tables;	
} hs_schema;
	
typedef struct {
	hs_uint num_schemas;
	hs_schema **schemas;
	hs_uint num_roles;
	hs_role **roles;
	hs_uint num_users;
	hs_user **users;
} hs_catalog;

#endif
